﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XTYAPI.PLC
{
    /// <summary>
    /// 复位优先指令
    /// </summary>
    public class RS
    {
        bool s, r, outSr;
        //如果S和R输入调用计算会导致无法计算SR都为true的情况
        /// <summary>
        /// 置位条件输入
        /// </summary>
        public bool S { get { return s; } set { s = value; } }
        /// <summary>
        /// 复位条件输入
        /// </summary>
        public bool R { get { return r; } set { r = value; } }
        /// <summary>
        /// 结果输出置位优先
        /// </summary>
        public bool OutSR { get { CalSR(); return outSr; } }
        /// <summary>
        /// 计算触发器
        /// </summary>
        void CalSR()
        {
            if (R & !S)
            {
                outSr = false;
            }
            else if (!R & S)
            {
                outSr = true;
            }
            else if (R & S)
            {
                outSr = false;
            }
           
        }
    }
}
